<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich">

<ui:composition template="../template.xhtml">
	<ui:define name="content">
	   
		<rich:panel>
	<f:facet name="header">
		<h:outputText value="#{stockItemsEditorBean.title}" />
	</f:facet>
	
	<h:form>
	<h:messages />
   	<h:panelGrid columns="3">
    	<h:outputText value="Supplier:" />
    	<rich:select id="supplierSelect" value="#{stockItemsEditorBean.supplier}" converter="#{supplierConverter}" required="true" requiredMessage="Supplier is required">
    		<f:selectItems value="#{stockItemsEditorBean.suppliers}" var="supplier" itemLabel="#{supplier.name}" itemValue="#{supplier}" itemValueAsString="#{supplier.id}" />
    	</rich:select>
    	<rich:message for="supplierSelect" />
    	<h:outputText value="Delivery date:" />
    		<rich:calendar value="#{stockItemsEditorBean.deliveryDate}" id="deliveryDate" locale="#{calendarBean.calendarLocale}" datePattern="#{calendarBean.calendarPattern}" cellWidth="24px" cellHeight="22px" style="width:200px" required="true" requiredMessage="Delivery date is required." />
    	<rich:message for="deliveryDate" />
    	<h:outputText value="Stock type:" />
    	<rich:select id="stockType" value="#{stockItemsEditorBean.stockType}" converter="#{stockTypeConverter}">
    		<f:selectItems value="#{stockItemsEditorBean.stockTypes}" var="stockType" itemLabel="#{stockType.name} (#{stockType.productClass}) #{stockType.price}" itemValue="#{stockType}" itemValueAsString="#{stockType.id}" />
    	</rich:select>
    	<rich:message for="stockType" />
    </h:panelGrid>
    
    <!-- Tabulka umiestneni -->
    <a4j:commandLink action="#{slotStockItemEditorBean.setEditorObjects(stockItemsEditorBean.selectedItem, null)}" value="Add">
		
	</a4j:commandLink>
    <rich:dataTable value="#{stockItemsEditorBean.slotStockItems}" var="slotStock"
					iterationStatusVar="it" id="tableSlotStock"
					rowClasses="odd-row, even-row" styleClass="stable"
					rows="#{SlotStockItemsBean.rowsPerPage}">
		<f:facet name="header">
			<rich:columnGroup>
				<rich:column colspan="4">
					<h:outputText value="Occupied slots" />
				</rich:column>
			</rich:columnGroup>
		</f:facet>
		
		<rich:column sortBy="#{slotStock.slot.name} / #{slotStock.slot.capacity}" id="slotName"
			sortOrder="#{slotStockItemSortingBean.slotOrder}">
			<f:facet name="header">
				<a4j:commandLink value="Slot" render="tableSlotStock"
					action="#{slotStockItemSortingBean.sortBySlot}" />
			</f:facet>
			<h:outputText value="#{slotStock.slot.name} / #{slotStock.slot.capacity}" />
		</rich:column>
		<rich:column sortBy="#{slotStock.placingDate}" id="slotPlacingDate"
			sortOrder="#{slotStockItemSortingBean.placingDateOrder}">
			<f:facet name="header">
				<a4j:commandLink value="Placing date" render="tableSlotStock"
					action="#{slotStockItemSortingBean.sortByPlacingDate}" />
			</f:facet>
			<h:outputText value="#{slotStock.placingDate}" />
		</rich:column>
		<rich:column sortBy="#{slotStock.amount} kg" id="slotAmount"
			sortOrder="#{slotStockItemSortingBean.slotOrder}">
			<f:facet name="header">
				<a4j:commandLink value="Amount" render="tableSlotStock"
					action="#{slotStockItemSortingBean.sortByAmount}" />
			</f:facet>
			<h:outputText value="#{slotStock.ammount}" />
		</rich:column>
		<rich:column>
			<!-- Linka na Vymazanie zaznamu -->
			<h:commandLink value="Edit" action="edit_slot_stock">
					<f:setPropertyActionListener target="#{slotStockItemEditorBean.stockItem}" value="#{stockItemsEditorBean.selectedItem}" />
					<f:setPropertyActionListener target="#{slotStockItemEditorBean.slotsStockItem}" value="#{slotStock}" />
			</h:commandLink>
			<!-- Linka na Vymazanie zaznamu -->
			<a4j:commandLink execute="@this" render="confirmPane"
				oncomplete="#{rich:component('confirmPane')}.show()"
				value="Delete">
				<f:setPropertyActionListener target="#{slotStockItemConfirmDeleteDialog.stockItem}" value="#{stockItemsEditorBean.selectedItem}" />
				<f:setPropertyActionListener target="#{slotStockItemConfirmDeleteDialog.slotStockItem}" value="#{slotStock}" />
			</a4j:commandLink>
		</rich:column>
	</rich:dataTable>
	
	<rich:popupPanel id="confirmPane" header="#{slotsConfirmDeleteDialogBean.title}"
				autosized="true">
      	<h:outputText value="#{slotStockItemConfirmDeleteDialog.question}" /><br />
		<a4j:commandButton value="Yes"
			action="#{slotStockItemConfirmDeleteDialog.submit}" render="tableSlotStock"
			execute="confirmPane"
			oncomplete="#{rich:component('confirmPane')}.hide();" />
		<a4j:commandButton value="No"
			onclick="#{rich:component('confirmPane')}.hide(); return false;" />
	</rich:popupPanel>
	<!-- Koniec tabulka umiestneni -->
    
    <!-- Ovladacie tlacitka -->
    <a4j:commandButton value="Save" action="#{stockItemsEditorBean.save}" /> 
	<a4j:commandButton value="Cancel" immediate="true" action="#{stockItemsEditorBean.cancel}" />
    </h:form>
    
    </rich:panel>

	</ui:define>
</ui:composition>
</html>